/**
 * Created by gemini on 2017/4/19.
 */
var myApp = angular.module('myApp', ['ui.bootstrap', 'ui.router', 'ngCookies'], function ($httpProvider) {
    $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
    $httpProvider.defaults.withCredentials = false;
    // Override $http service's default transformRequest
    $httpProvider.defaults.transformRequest = [function (data) {
        /**
         * The workhorse; converts an object to x-www-form-urlencoded serialization.
         * @param {Object} obj
         * @return {String}
         */
        var param = function (obj) {
            var query = '';
            var name, value, fullSubName, subName, subValue, innerObj, i;

            for (name in obj) {
                value = obj[name];

                if (value instanceof Array) {
                    for (i = 0; i < value.length; ++i) {
                        subValue = value[i];
                        fullSubName = name + '[' + i + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                } else if (value instanceof Object) {
                    for (subName in value) {
                        subValue = value[subName];
                        fullSubName = name + '[' + subName + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                } else if (value !== undefined && value !== null) {
                    query += encodeURIComponent(name) + '='
                        + encodeURIComponent(value) + '&';
                }
            }
            return query.length ? query.substr(0, query.length - 1) : query;
        };

        //alert(data);
        return angular.isObject(data) && String(data) !== '[object File]'
            ? param(data)
            : data;
    }];
})
    .config(function ($stateProvider, $urlRouterProvider) {
        $stateProvider.state('login', {
            url: '/login',
            templateUrl: 'views/login.html',
            controller: 'loginCtrl'
        })
            .state('main', {
                url: '/main',
                templateUrl: 'views/main.html',
                controller: 'mainCtrl'
            })

            /**会员部分**/
            .state('main.memberList', {
                url: '/main.memberList',
                templateUrl: 'views/member/memberList.html',
                controller: 'memberlistCtrl'
            })
            .state('main.memberDetail', {
                url: '/main.memberDetail/:member_id',
                templateUrl: 'views/member/memberDetail.html',
                controller: 'memberdetailCtrl'
            })
            .state('main.editModal',{
                url:'/main.editModal',
                templateUrl:'views/member/memberEditModal.html'
            })
            .state('main.addModal',{
                url:'/main.addModal',
                templateUrl:'views/member/memberAddModal.html'
            })

            /***场馆部分***/
            .state('main.venueList',{
                url: '/main.venueList',
                templateUrl: 'views/venue/venueList.html',
                controller: 'venuelistCtrl'
            })

            .state('main.venueDetail',{
                url: '/main.venueDetail',
                templateUrl: 'views/venue/venueDetail.html',
                controller: 'venuedetailCtrl'
            })


            /***教室部分***/
            .state('main.roomList',{
                url: '/main.roomList',
                templateUrl: 'views/room/roomList.html',
                controller: 'roomlistCtrl'
            })
            .state('main.roomModal',{
                url: '/main.roomModal',
                templateUrl: 'views/room/roomModal.html'
            })


            /***闸机部分***/
            .state('main.gateList',{
                url: '/main.gateList',
                templateUrl: 'views/gate/gateList.html',
                controller:'gatelistCtrl'
            });
        $urlRouterProvider.otherwise('/login')
    });